package cn.taokuaidi.wangwang.client.context;

import cn.taokuaidi.wangwang.client.constants.AppEvents;
import cn.taokuaidi.wangwang.client.data.Request;
import cn.taokuaidi.wangwang.client.model.OrderDO;
import cn.taokuaidi.wangwang.client.reader.OrderReader;
import cn.taokuaidi.wangwang.client.smart.AppConfig;

import com.extjs.gxt.ui.client.data.BasePagingLoader;
import com.extjs.gxt.ui.client.data.HttpProxy;
import com.extjs.gxt.ui.client.data.LoadEvent;
import com.extjs.gxt.ui.client.data.ModelData;
import com.extjs.gxt.ui.client.mvc.Dispatcher;
import com.extjs.gxt.ui.client.store.ListStore;

/**
 * @author 嘉陵江里捉鱼 email:tang7259@163.com
 *@version 1.0
 *@time Nov 3, 2008 10:19:59 AM
 */
public class SellerDataEventContext {

    private static BasePagingLoader loader;
    private static ListStore<OrderDO> store;

    public static void load() {
        AppConfig appConfig = AppConfig.getDefaultAppConfig();
        HttpProxy proxy = new HttpProxy(Request.getSellerBuilder());
        loader = new BasePagingLoader(proxy, new OrderReader<ModelData>());
        loader.load(0, appConfig.sellerGridPageSize);
        store = new ListStore<OrderDO>(loader) {

            @Override
            protected void onLoad(LoadEvent le) {
                super.onLoad(le);
                Dispatcher.forwardEvent(AppEvents.SELLER_DATA_LOADED);
            }

        };

    }

    public static BasePagingLoader getLoader() {
        return loader;
    }

    public static ListStore<OrderDO> getStore() {
        return store;
    }

}
